
import Button from '../../components/button/button';
import { useDispatch } from 'react-redux';
import { logout } from '../../store/auth/authorisation.slice';
import { useNavigate } from 'react-router-dom';
import { useAppSelector } from '../../store/hooks';
import { useEffect } from 'react';
import { fetchUserMeSlice } from '../../store/user/use.actions';

export const User = () => {
	const dispatch = useDispatch();
	const {user} = useAppSelector(state => state.userMe);
	useEffect(() => {
		console.log('test');
		dispatch(fetchUserMeSlice());
	}, [dispatch]);
	const navigate = useNavigate();
	const logoutUser = () => {
		dispatch(logout());
		navigate('/');
	};
	return (
		<div>
			<p>Личный кабинет пользователя {user.fullName}</p>
			<Button onClick={logoutUser}>Выход</Button>
		</div>
	);
};
